/** FASSIT (Forms of Selective Attention in Intelligent Transportation Systems)
 * Computational Creativity and Digital Media
 * Cognitive and Media Systems Group
 * Centre for Informatics and Systems of the University of Coimbra (CISUC)
 *
 * Copyright (c) 2010-2013 University of Coimbra, Portugal
 * All rights reserved.
 */

package agent.Metrics.Uncertainty;

import java.util.ArrayList;

import poi.Uncertainty.*;

/**
 * This class is used to store the Agent's past knowledge from the database
 * 
 * @author Hernani Costa
 * @version 0.1 date: 28/01/2013
 */
public class PastUncertaintyValues {
	private ArrayList<UncertaintyDaysOff> listUncertaintyDayOff;
	private ArrayList<UncertaintyPrice> listUncertaintyPrice;
	private ArrayList<UncertaintySchedule> listUncertaintySchedule;
	private UncertaintyDaysOff uncertaintyDayOff;
	private UncertaintyPrice uncertaintyPrice;
	private UncertaintySchedule uncertaintySchedule;

	/**
	 * ------------------------------------------------------------------------
	 * Constructor class
	 * ------------------------------------------------------------------------
	 */
	public PastUncertaintyValues() {
		listUncertaintyDayOff = new ArrayList<UncertaintyDaysOff>();
		listUncertaintyPrice = new ArrayList<UncertaintyPrice>();
		listUncertaintySchedule = new ArrayList<UncertaintySchedule>();
	}

	/**
	 * ------------------------------------------------------------------------
	 * This class stores the uncertainty values from the database
	 * ------------------------------------------------------------------------
	 * 
	 * @param uncertaintyDayOff
	 *            - uncertainty value for the parameter DayOff
	 * @param uncertaintyPrice
	 *            - uncertainty value for the parameter Price
	 * @param uncertaintySchedule
	 *            - uncertainty value for the parameter Schedule
	 */
	public void addUncertainty(UncertaintyDaysOff uncertaintyDayOff,
			UncertaintyPrice uncertaintyPrice,
			UncertaintySchedule uncertaintySchedule) {
		listUncertaintyDayOff.add(uncertaintyDayOff);
		listUncertaintyPrice.add(uncertaintyPrice);
		listUncertaintySchedule.add(uncertaintySchedule);
		this.uncertaintyDayOff = getValuesForDaysOff();
		this.uncertaintyPrice = getValuesForPrice();
		this.uncertaintySchedule = getValuesForSchedule();
	}

	private UncertaintyDaysOff getValuesForDaysOff() {
		UncertaintyDaysOff uncertaintyDayOff = null;
		int divisor = listUncertaintyDayOff.size();
		double monday = 0.0, tuesday = 0.0, wednesday = 0.0, thusday = 0.0, friday = 0.0, saturday = 0.0, sunday = 0.0;

		for (UncertaintyDaysOff temp : listUncertaintyDayOff) {
			monday += temp.getMonday();
			tuesday += temp.getTuesday();
			wednesday += temp.getWednesday();
			thusday += temp.getThursday();
			friday += temp.getFriday();
			saturday += temp.getSaturday();
			sunday += temp.getSunday();
		}
		uncertaintyDayOff = new UncertaintyDaysOff(sunday / divisor, monday
				/ divisor, tuesday / divisor, wednesday / divisor, thusday
				/ divisor, friday / divisor, saturday / divisor);

		return uncertaintyDayOff;
	}

	private UncertaintyPrice getValuesForPrice() {
		UncertaintyPrice uncertaintyPrice = null;
		int divisor = listUncertaintyPrice.size();
		double cheap = 0.0, average = 0.0, expensive = 0.0;

		for (UncertaintyPrice temp : listUncertaintyPrice) {
			cheap += temp.getCheap();
			average += temp.getAverage();
			expensive += temp.getExpensive();
		}
		uncertaintyPrice = new UncertaintyPrice(cheap / divisor, average
				/ divisor, expensive / divisor);

		return uncertaintyPrice;
	}

	private UncertaintySchedule getValuesForSchedule() {
		UncertaintySchedule uncertaintySchedule = null;
		int divisor = listUncertaintySchedule.size();
		double morning = 0.0, afternoon = 0.0, night = 0.0;

		for (UncertaintySchedule temp : listUncertaintySchedule) {
			morning += temp.getMorning();
			afternoon += temp.getAfternoon();
			night += temp.getNight();
		}
		uncertaintySchedule = new UncertaintySchedule(morning / divisor,
				afternoon / divisor, night / divisor);

		return uncertaintySchedule;
	}

	// ------------------------------------------------------------------------
	// ------------------------GETs and SETs-----------------------------------
	// ------------------------------------------------------------------------
	public UncertaintyDaysOff getUncertaintyDayOff() {
		return uncertaintyDayOff;
	}

	public UncertaintyPrice getUncertaintyPrice() {
		return uncertaintyPrice;
	}

	public UncertaintySchedule getUncertaintySchedule() {
		return uncertaintySchedule;
	}
}
